package com.ruyuan.eshop.order.service;

import com.ruyuan.eshop.order.dao.OrderItemDAO;
import com.ruyuan.eshop.order.domain.entity.AfterSaleItemDO;
import com.ruyuan.eshop.order.domain.entity.OrderItemDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author lxg
 * @Description:
 * @date 2022/4/1615:40
 */
@Component
public class AfterSaleAmountService {

    @Autowired
    public OrderItemDAO orderItemDAO;

    /**
     * 计算订单条目缺品实际退款金额
     * 计算公式：（缺品数量/下单数量） * 原付款金额
     *
     * @param orderItem
     * @param lackNum
     * @return
     */
    public Integer calculateOrderItemLackRealRefundAmount(OrderItemDO orderItem, Integer lackNum) {

        double rate= lackNum/orderItem.getSaleQuantity().doubleValue();
        //金额向上取整
        Integer refundAmount=Double.valueOf(Math.ceil(orderItem.getPayAmount()*rate)).intValue();
        return refundAmount;
    }

    /**
     * 计算订单总申请退款金额
     *
     * @param lackItems
     * @return
     */
    public Integer calculateOrderLackApplyRefundAmount(List<AfterSaleItemDO> lackItems) {
        Integer applyRefundAmount = 0;

        for (AfterSaleItemDO lackItem : lackItems) {
            applyRefundAmount+=lackItem.getApplyRefundAmount();
        }
        return applyRefundAmount;
    }

    /**
     * 计算订单总实际退款金额
     *
     * @param lackItems
     * @return
     */
    public Integer calculateOrderLackRealRefundAmount(List<AfterSaleItemDO> lackItems) {
        Integer realRefundAmount=0;
        for (AfterSaleItemDO lackItem : lackItems) {
            realRefundAmount+=lackItem.getRealRefundAmount();
        }
        return realRefundAmount;
    }




    }
